package be.aquafin.klipdf.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.apache.commons.lang3.StringUtils;

import be.aquafin.klipdf.model.Node;
import be.aquafin.klipdf.model.Pipe;

/**
 * Databaseimplementatie DataDao
 * 
 * @author user2080
 * 
 */
public class DataDaoImpl implements DataDao {

	@PersistenceContext(unitName = "jagisInPersistenceUnit")
	private EntityManager jagisInEntityMgr;

	public List<Pipe> getPipes(List<String> keys) {
		String whereClause = createWhereClause(keys);
		return jagisInEntityMgr.createQuery("from Pipe p where p.uid in (" + whereClause + ")", Pipe.class).getResultList();
	}

	public List<Node> getNodes(List<String> keys) {
		String whereClause = createWhereClause(keys);
		return jagisInEntityMgr.createQuery("from Node n where n.uid in (" + whereClause + ")", Node.class).getResultList();
	}

	private String createWhereClause(List<String> keys) {
		return "'" + StringUtils.join(keys, "','") + "'";
	}

}
